package org.example.mybatis3.controller;

import org.example.mybatis3.entity.blog.Blog;
import org.example.mybatis3.service.BlogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/blog")
public class BlogController {
    @Autowired
  private BlogService blogService;
    @GetMapping("/{id}")
    public Blog findById(@PathVariable Long id) {
        return blogService.selectBlogWithAuthor(id);
    }

    @GetMapping("/select/{id}")
    public Blog findByIdBySelect(@PathVariable Long id) {
        return blogService.selectBlogWithAuthorBySelect(id);
    }

    @GetMapping
    public List<Blog> findAll() {
        return blogService.selectAllBlogs();
    }

    @GetMapping("/withAuthor")
    public List<Blog> findAllWithAuthor() {
        return blogService.selectAllBlogsWithAuthor();
    }

    @GetMapping("/posts/select/{id}")
    public Blog findByIdWithPostsBySelect(@PathVariable Long id) {
        return blogService.selectBlogWithPostsBySelect(id);
    }

    @GetMapping("/posts/{id}")
    public Blog findByIdWithPosts(@PathVariable Long id) {
        return blogService.selectBlogWithPosts(id);
    }

}
